package com.scott.singleton.lesson03;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 不使用任何模式
 * 因为配置文件定义好后在运行过程中就不会变
 */
public class UserEntity {
	
	private String name;
	
	private int age;
	
	public UserEntity(){
		config();
	}
	
	private void config(){
		System.out.println("读取1次配置文件....");
		Properties ps = new Properties();
		
		InputStream in = null;
		try {
			in = UserEntity.class.getClassLoader().getResourceAsStream("com/scott/singleton/lesson03/config.properties");
			ps.load(in);
			this.name =ps.getProperty("name");
			this.age  =Integer.parseInt(ps.getProperty("age"));
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				if(null != in){
					in.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "UserEntity [name=" + name + ", age=" + age + "]";
	}
	
	
	

}
